<template>
  <div id="login" v-title data-title="登录 - 花花世界">
    <!--<video preload="auto" class="me-video-player" autoplay="autoplay" loop="loop">
          <source src="../../static/vedio/sea.mp4" type="video/mp4">
      </video>-->

    <div class="me-login-box me-login-box-radius">
      <h1>怪兽编程 登录</h1>

      <el-form ref="userForm" :model="userForm" :rules="rules">
        <el-form-item prop="account">
          <el-input placeholder="用户名" v-model="userForm.account"></el-input>
        </el-form-item>

        <el-form-item prop="password">
          <el-input placeholder="密码" type="password" v-model="userForm.password"></el-input>
        </el-form-item>


        <el-breadcrumb  separator-class="el-icon-arrow-right" class="changeAco">

          <div class="remember"><input type="checkbox" name="ball" value="football" id="2"/><span>记住密码</span></div>
          <el-breadcrumb-item :to="{ path: 'register' }"><div style="cursor: pointer; margin-top: -20px; font-size: 8px;margin-left: 80px; color: #5daf34;">
            <span style="color: #9b9b9b;margin-left: 15px;">没有账号？</span>立即注册</div>
          </el-breadcrumb-item>
        </el-breadcrumb>

        <el-form-item size="small" class="me-login-button">
          <el-button type="primary" class="submit"  @click.native.prevent="login('userForm')">登录</el-button>
        </el-form-item>

      </el-form>

    </div>
  </div>
</template>

<script>
// 打开验证码窗口

  export default {
    name: 'Login',
    data() {
      return {
        userForm: {
          account: '',
          password: ''
        },
        rules: {
          account: [
            {required: true, message: '请输入用户名', trigger: 'blur'},
            {max: 10, message: '不能大于10个字符', trigger: 'blur'}
          ],
          password: [
            {required: true, message: '请输入密码', trigger: 'blur'},
            {max: 10, message: '不能大于10个字符', trigger: 'blur'}
          ]
        }
      }
    },
    methods: {
      // 验证码功能


      login(formName) {

        this.$Captcha.show();
        this.$bus.$on('getTicket', res => {
          // 返回结果
          // ret         Int       验证结果，0：验证成功。2：用户主动关闭验证码。
          // ticket      String    验证成功的票据，当且仅当 ret = 0 时 ticket 有值。
          // CaptchaAppId       String    验证码应用ID。
          // bizState    Any       自定义透传参数。
          // randstr     String    本次验证的随机串，请求后台接口时需带上。
          if (res.ret === 0) {
            //验证成功的操作
            let that = this

            this.$refs[formName].validate((valid) => {
              if (valid) {

                that.$store.dispatch('login', that.userForm).then(() => {
                  that.$router.go(-1)
                }).catch((error) => {
                  if (error !== 'error') {
                    that.$message({message: error, type: 'error', showClose: true});
                  }
                })
              } else {
                return false;
              }
            });
          } else {
            this.$notify.warning('请通过验证')
          }
          this.$bus.$off('getTicket')
        })

      },

    }
  }
</script>

<style scoped>
  #login {
    min-width: 100%;
    min-height: 100%;
  }
  .me-video-player {
    background-color: transparent;
    width: 100%;
    height: 100%;
    object-fit: fill;
    display: block;
    position: absolute;
    left: 0;
    z-index: 0;
    top: 0;
  }

  .me-login-box {
    position: absolute;
    width: 300px;
    height: 250px;
    background-color: white;
    margin-top: 150px;
    margin-left: -180px;
    left: 50%;
    padding: 30px;
  }

  .me-login-box-radius {
    border-radius: 10px;
    box-shadow: 0px 0px 1px 1px rgba(161, 159, 159, 0.2);
  }

  .me-login-box h1 {
    text-align: center;
    font-size: 24px;
    margin-bottom: 20px;
    vertical-align: middle;
  }

  .me-login-design {
    text-align: center;
    font-family: 'Open Sans', sans-serif;
    font-size: 18px;
  }

  .me-login-design-color {
    color: #5FB878 !important;
  }

  .me-login-button {
    text-align: center;
  }

  .me-login-button button {
    width: 100%;
  }
  /* 记住密码+切换登录*/
  .changeAco{
    clear: both;
    display: flex;
    align-items: center;
    height:20px;
    margin-top: 21px;
    margin-bottom:10px;
  }
  .remember {
    margin-top: -24px;
    display: flex;
    align-items: center;
    font-size: 10px;
    margin-left: 8px;
    width: 80px;
  }
    span{
      padding-left:4px;
    }
    /*提交按钮*/
    .submit{
      width: 80%;
    }


</style>
